package com.jianggujin.demo.action;

import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.jianggujin.modulelink.action.JAction;
import com.jianggujin.modulelink.action.JModuleContext;
import com.jianggujin.modulelink.config.JModuleConfig;
import com.jianggujin.modulelink.config.JMultiVersionModuleConfig;
import com.jianggujin.modulelink.exception.JModuleLinkException;
import com.jianggujin.modulelink.support.annotation.JActionComponent;

@Component
@JActionComponent(isDefault = true)
public class HelloAction implements JAction {
    private static final long startTime = System.currentTimeMillis();

    @Override
    public Object execute(Object in) throws JModuleLinkException {
        Map<String, String> result = new LinkedHashMap<String, String>();
        JModuleConfig moduleConfig = JModuleContext.getModuleConfig();
        result.put("moduleName", moduleConfig.getModuleName());
        if (moduleConfig instanceof JMultiVersionModuleConfig) {
            result.put("version", ((JMultiVersionModuleConfig) moduleConfig).getVersion());
        }
        result.put("description", moduleConfig.getDescription());
        result.put("loader", getClass().getClassLoader().toString());
        result.put("action", getClass().getName());
        result.put("actions", String.valueOf(JModuleContext.getActionNames()));
        result.put("startTime", startTime + "");
        return result;
    }
}
